<?php
session_start();

// 1.连接数据库
$conn = mysql_connect("localhost", "root", "") or die("数据库连接失败");
$db = mysql_select_db("jkxy", $conn) or die("数据库选择失败");
mysql_query("set names utf8");

// 2.获取用户的输入值
$username = $_POST['username'];
$password = $_POST['password'];
$image = strtoupper($_POST['image']);
$image2 = $_SESSION['pic'];

// 3.拼SQL语句，插入到数据库中
if(isset($_POST['submit'])){
	if($image == $image2){
		$sql = "insert into users(username, password) values('$username', md5($password))";
		mysql_query($sql);
// 		echo "<script>alert('注册成功'); window.location = './login.html';</script>";
		
		$rc = mysql_affected_rows();
		if($rc > 0){
			echo "<script>alert('注册成功'); window.location = './login.html';</script>";
		}else{
			echo "<script>alert('注册失败'); window.history.back();</script>";
		}
	}else{
		echo "<script>alert('验证码错误!');<script>";
	}
}
?>



















